package com.xbts.system.domain;


import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import com.xbts.common.annotation.Excel;
import com.xbts.common.utils.StringUtils;
import com.xbts.common.core.domain.BaseEntity;

/**
 * 首页产品信息对象 cn_home_product
 *
 * @author xbts
 * @date 2023-11-30
 */
@Data
@ApiModel("首页产品信息对象")
@TableName("cn_home_product")
public class CnHomeProduct extends BaseEntity {

    private static final long serialVersionUID=1L;

    /** id */
    @TableId
    private String id;

    /** 类型id */
    @Excel(name = "类型id")
    @ApiModelProperty("类型id")
    @NotEmpty(message = "类型id不能为空")
    private String typeId;

    /** 子类型id */
    @Excel(name = "子类型id")
    @ApiModelProperty("子类型id")
    private String childrenTypeId;

    /** 产品名称 */
    @Excel(name = "产品名称")
    @ApiModelProperty("产品名称")
    @NotEmpty(message = "产品名称不能为空")
    private String productName;

    /** 产品图标 */
    @Excel(name = "产品图标")
    @ApiModelProperty("产品图标")
    private String productImg;

    /** 产品链接 */
    @Excel(name = "产品链接")
    @ApiModelProperty("产品链接")
    @NotEmpty(message = "产品链接不能为空")
    private String productUrl;

    /** 产品简介 */
    @Excel(name = "产品简介")
    @ApiModelProperty("产品简介")
    private String productIntroduction;

    /** 状态：(1上架，2下架) */
    @Excel(name = "状态(1上架，2下架)")
    @ApiModelProperty("状态：(1上架，2下架)")
    private String status;

    /** 排序（数值越小越靠前） */
    @Excel(name = "排序", readConverterExp = "数=值越小越靠前")
    @ApiModelProperty("排序")
    @NotNull(message = "排序不能为空")
    private Integer sort;

    @TableField(exist = false)
    private String typeName;
    @TableField(exist = false)
    private String childrenTypeName;

    public<T> QueryWrapper<T> queryWrapper(){
        QueryWrapper<T> queryWrapper=new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(typeId),"type_id",typeId);
        queryWrapper.like(StringUtils.isNotEmpty(productName),"product_name",productName);
        queryWrapper.like(StringUtils.isNotEmpty(productImg),"product_img",productImg);
        queryWrapper.like(StringUtils.isNotEmpty(productUrl),"product_url",productUrl);
        queryWrapper.like(StringUtils.isNotEmpty(productIntroduction),"product_introduction",productIntroduction);
        queryWrapper.like(StringUtils.isNotEmpty(status),"status",status);
        queryWrapper.orderByAsc("sort");
        queryWrapper.orderByDesc("update_time");
        return queryWrapper;
    }
}